// run: $exec < input
#include <iostream>
#include <string>
#include <utility>

int const maxn = 202;
int a[maxn];
bool vis[maxn];
char ch[maxn];
char ans[maxn];
int circle[maxn];
int len = 0;
int n;

void init()
{
	for (int i = 1; i <= n; i++) {
		ch[i] = ' ';
		vis[i] = false;
	}
}

void get_circle(int x)
{
	len = 0; circle[len++] = x;
	vis[x] = true;
	for (int i = a[x]; i != x; i = a[i]) {
		circle[len++] = i;
		vis[i] = true;
	}
}

int main()
{
	std::ios::sync_with_stdio(false);
	while(std::cin >> n && n) {
		for (int i = 1; i <= n; i++) std::cin >> a[i];

		std::string s;
		for (int k; std::cin >> k && k; ) {
			init();
			std::getline(std::cin, s);
//			std::cout << "== k = " << k << " ::" << s << "==\n";
			for (int i = 1; i < (int)s.size(); i++)
				ch[i] = s[i];

			for (int i = 1; i <= n; i++) {
				if (vis[i]) continue;
				get_circle(i);
				int tk = k % len;
				for (int j = 0; j < len; j++)
					ans[circle[(j + tk) % len]] = ch[circle[j]];
			}

			for (int i = 1; i <= n; i++)
				std::cout << ans[i];
			std::cout << '\n';
		}
		std::cout << '\n';
	}
}

